// map函数
const map = (arr, fn) => {
  let results = [];
  // for (let i = 0; i < arr.length; i++) {
  //   results.push(fn(arr[i]));
  // }
  for (let item of arr) {
    results.push(fn(item));
  }
  return results;
}
let arr = [1, 3, 4, 5];
console.log("所有的元素都平方处理: " + map(arr, (item) => item * item));

// some函数
const some = (arr, fn) => {
  let flag = false;
  for (let item of arr) {
    if (fn(item)) {
      flag = true;
      break;
    }
  }
  return flag;
}
console.log("是否有是偶数的值: " + some(arr, (item) => item % 2 == 0));
console.log("是否有小于0的值: " + some(arr, (item) => item < 0));
// every函数
const every = (arr, fn) => {
  let flag = true;
  for (let item of arr) {
    if (!fn(item)) {
      flag = false;
      break;
    }
  }
  return flag;
}
console.log("是否都是偶数: " + every(arr, (item) => item % 2 == 0));
console.log("是否都大于0: " + every(arr, (item) => item > 0));